﻿using UnityEngine;

public static class Utility
{
    private static readonly string[] TargetAbbreviation = { "K", "M", "G", "T", "P", "E", "Z", "Y", "B", "G" };
    public static void Shuffle<T>(ref T[] list)
    {
        if (list.Length <= 1)
            return;

        for(int i=list.Length - 1;i>0;i--)
        {
            int random = Random.Range(0, i);
            T temp = list[i];
            list[i] = list[random];
            list[random] = temp;
        }

        for (int i = list.Length - 1; i > 0; i--)
        {
            int random = Random.Range(0, i);
            T temp = list[i];
            list[i] = list[random];
            list[random] = temp;
        }
    }

    public static Color RandomColor()
    {
        float randomNumber = Random.Range(0.325f, 1f);
        float[] colorArray = { 0.325f, 1, randomNumber };

        Utility.Shuffle(ref colorArray);

        return new Color(colorArray[0], colorArray[1], colorArray[2]);

    }

    public static Vector2 RandomVector2()
    {
        return Random.insideUnitCircle.normalized;
    }

    public static string CellNumber(int power)
    {
        string result = "";
        int showNumber = 0;
        if (power >= 12)
        {
            int tempPower = power % 10; // 19 20 21
            int unit = power / 10 - 1;
            showNumber = (1 << tempPower);
            
            result = string.Concat(showNumber.ToString(), TargetAbbreviation[unit]);
        }
        else
        {
            showNumber = (1 << power);
            result = showNumber.ToString();
        }
        return result;
    }
    
    public static int CellNumberByInt(int power)
    {
        int result = 0;
        int showNumber = 0;
        if (power >= 12)
        {
            int tempPower = power % 10; // 19 20 21
            int unit = power / 10 - 1;
            showNumber = (1 << tempPower);
            
            result = showNumber;
        }
        else
        {
            showNumber = (1 << power);
            result = showNumber;
        }
        return result;
    }
}
